/* GUI CONVERTED from reuvps1.p (converter v1.75) Fri Jun 22 15:25:46 2001 */
/* reuvps1.p - REPETITIVE - POST FLOORSTOCK EXPENSE                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.6.1.5 $                                                           */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/31/95   BY: WUG *G0K0*                */
/* REVISION: 7.3      LAST MODIFIED: 01/19/96   BY: emb *G1K9*                */
/* REVISION: 8.5      LAST MODIFIED: 12/10/95   BY: sxb *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 03/13/96   BY: jym *G1GD*                */
/* REVISION: 8.5      LAST MODIFIED: 02/18/97   BY: *J1HC*   Russ Witt        */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.6.1.5 $    BY: Hualin Zhong   DATE: 06/15/01 ECO: *N0ZF*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reuvps1_p_2 "Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE reuvps1_p_3 "Cumulative!Expense"
/* MaxLen: Comment: */

&SCOPED-DEFINE reuvps1_p_4 "Expense!To Post"
/* MaxLen: Comment: */

&SCOPED-DEFINE reuvps1_p_5 "Standard!Qty Per"
/* MaxLen: Comment: */

&SCOPED-DEFINE reuvps1_p_6 "Qty To Expense"
/* MaxLen: Comment: */

&SCOPED-DEFINE reuvps1_p_7 "Qty Previously!Expensed"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/* Added 'no-undo' to variable and parameter declarations */
define input parameter cumwo_lot as character no-undo.
define input parameter eff_date as date no-undo.

define input parameter zero_unposted_exp as logical no-undo.
define input parameter zero_cum_exp as logical no-undo.
define input-output parameter orderprinted as logical no-undo.

define shared workfile work_op_recids no-undo
   field work_op_recid as recid.

define new shared variable op_recno as recid.
define new shared variable opgltype like opgl_type.
define new shared variable ref like glt_ref.
define new shared variable sf_cr_acct like dpt_lbr_acct.
define new shared variable sf_cr_sub like dpt_lbr_sub.
define new shared variable sf_cr_cc like dpt_lbr_cc.
define new shared variable sf_dr_acct like dpt_lbr_acct.
define new shared variable sf_dr_sub like dpt_lbr_sub.
define new shared variable sf_dr_cc like dpt_lbr_cc.
define new shared variable sf_entity like en_entity.
define new shared variable sf_gl_amt like tr_gl_amt.

define variable cum_exp like trgl_gl_amt no-undo.
define variable dept as character no-undo.
define variable display_count as integer no-undo.
define variable emp as character no-undo.
define variable exp_to_post like trgl_gl_amt no-undo.
define variable first_of_op like mfc_logical no-undo.
define variable item_is_floorstock like mfc_logical no-undo.
define variable qty_per as decimal no-undo.
define variable qty_prev_exp like wr_qty_cumproc no-undo.
define variable qty_to_exp like wr_qty_cumproc no-undo.
define variable shift as character no-undo.
define variable std_issue_qty like wr_qty_cumproc no-undo.
define variable trans_type as character no-undo.
define variable glx_set like cs_set no-undo.
define variable glx_mthd like cs_method no-undo.
define variable cur_set like cs_set no-undo.
define variable cur_mthd like cs_method no-undo.
define variable ophist_recid as recid no-undo.

FORM /*GUI*/ 
   wr_op
   wr_qty_cumproc
   wod_part
   wod_bom_qty     column-label {&reuvps1_p_5}
   qty_prev_exp    column-label {&reuvps1_p_7}
   qty_to_exp      column-label {&reuvps1_p_6}
   wod_bom_amt     column-label {&reuvps1_p_2}
   cum_exp         column-label {&reuvps1_p_3}
   exp_to_post     column-label {&reuvps1_p_4}
with STREAM-IO /*GUI*/  frame f_a width 132
title color normal (getFrameTitle("FLOORSTOCK_COMPONENT_EXPENSE",39)).

/* SET EXTERNAL LABELS */
setFrameLabels(frame f_a:handle).

find wo_mstr where wo_lot = cumwo_lot exclusive-lock.
find si_mstr where si_site = wo_site no-lock.
sf_entity = si_entity.

/*DETERMINE COSTING METHOD*/
{gprun.i ""csavg01.p"" "(input  wo_part,
                         input  wo_site,
                         output glx_set,
                         output glx_mthd,
                         output cur_set,
                         output cur_mthd)" }

find first gl_ctrl no-lock.
assign
   display_count = 0
   first_of_op   = no.

for each wr_route exclusive-lock where wr_lot = wo_lot,
each wod_det exclusive-lock
where wod_lot = wr_lot
  and wod_op = wr_op
break by wod_lot by wod_op by wod_part with frame f_a down:

   find pt_mstr where pt_part = wod_part no-lock.
   item_is_floorstock = not pt_iss_pol.

   find ptp_det where ptp_part = wod_part and ptp_site = wo_site
      no-lock no-error.

   if available ptp_det then item_is_floorstock = not ptp_iss_pol.

   if first-of(wod_op) then first_of_op = yes.

   if item_is_floorstock then do:

      dept = "".
      find wc_mstr where wc_wkctr = wr_wkctr and wc_mch = wr_mch
         no-lock no-error.
      if available wc_mstr then dept = wc_dept.

      find qad_wkfl
      where qad_key1 = "MFWORLA"
       and qad_key2  = wod_lot + wod_part + string(wod_op)
      exclusive-lock no-error.

      if not available qad_wkfl then do:
         create qad_wkfl.

         assign
            qad_key1      = "MFWORLA"
            qad_key2      = wod_lot + wod_part + string(wod_op)
            qad_decfld[2] = 1.
      end.

      qty_per = 0.
      if qad_charfld[1] = "s" then
         qty_per = wod_bom_qty.

      assign
         std_issue_qty = qty_per * wr_qty_cumproc
         qty_prev_exp  = qad_decfld[3]
         qty_to_exp    = std_issue_qty - qty_prev_exp
         cum_exp       = std_issue_qty * wod_bom_amt
         exp_to_post   = qty_to_exp * wod_bom_amt.
      /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
      {gprun.i ""gpcurrnd.p"" "(input-output cum_exp,
                                input gl_rnd_mthd)"}

      /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
      {gprun.i ""gpcurrnd.p"" "(input-output exp_to_post,
                                input gl_rnd_mthd)"}

      if (zero_unposted_exp = yes or exp_to_post <> 0)
         and (zero_cum_exp = yes or cum_exp <> 0) then do:

         if orderprinted = no then do:
            {gprun.i ""rewodisp.p"" "(input wo_lot)"}
            orderprinted = yes.
         end.

         display
            wr_op            when (first_of_op)
            wr_qty_cumproc   when (first_of_op)
            wod_part
            qty_per          @ wod_bom_qty
            qty_prev_exp
            qty_to_exp
            wod_bom_amt
            cum_exp
            exp_to_post WITH STREAM-IO /*GUI*/ .
         down 1.

         assign
            display_count = display_count + 1
            first_of_op   = no.

         if exp_to_post <> 0 then do:

            assign
               wod_qty_iss    = wod_qty_iss + qty_to_exp
               wod_mvuse_rval = wod_mvuse_rval + exp_to_post
               qad_decfld[3]  = std_issue_qty
               trans_type     = "FLOORSTK".

            {gprun.i ""reophist.p"" "(input  trans_type,
                                      input  wr_lot,
                                      input  wr_op,
                                      input  emp,
                                      input  wr_wkctr,
                                      input  wr_mch,
                                      input  dept,
                                      input  shift,
                                      input  eff_date,
                                      output ophist_recid)"}

            create work_op_recids.

            work_op_recid = ophist_recid.

            if recid(work_op_recids) > 0 then.

            find op_hist exclusive-lock
            where recid(op_hist) = ophist_recid.

            op_comment = wod_part.

            assign
               sf_dr_acct = wo_acct
               sf_dr_sub = wo_sub
               sf_dr_cc = wo_cc
               sf_cr_acct = wo_flr_acct
               sf_cr_sub = wo_flr_sub
               sf_cr_cc = wo_flr_cc
               sf_gl_amt = exp_to_post
               opgltype = trans_type
               op_recno = ophist_recid.

            {gprun.i ""sfopgl.p""}

            assign
               wo_wip_tot = wo_wip_tot + exp_to_post
               wr_mtl_ll_act = wr_mtl_ll_act + exp_to_post.

         end.

         accumulate cum_exp (total).
         accumulate exp_to_post (total).
      end.
   end.

   if last(wod_op) and display_count > 0 then do:
      underline cum_exp exp_to_post.
      down 1.

      display
         accum total cum_exp @ cum_exp
         accum total exp_to_post @ exp_to_post WITH STREAM-IO /*GUI*/ .
   end.
end.
